package com.example.demo.controller;

import com.example.demo.core.Result;
import com.example.demo.entity.ResourceFile;
import com.example.demo.service.ResourceFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 资源管理
 *
 * @author 叮当猫的百宝箱
 * @since 1.0
 */
@Tag(name = "资源管理", description = "资源管理")
@RestController
@RequestMapping("/resource")
@RequiredArgsConstructor
public class ResourceFileController {
    private final ResourceFileService resourceService;

    /**
     * 上传图片
     *
     * @param file 图片文件
     * @return API全局响应对象
     */
    @Operation(summary = "图片文件上传")
    @PostMapping("/image/upload")
    @PreAuthorize("hasAuthority('/resource/image/upload')")
    public Result<ResourceFile> uploadImage(MultipartFile file) {
        ResourceFile resource = resourceService.uploadImage(file);
        return Result.ok(resource);
    }

}
